import { ParticleSystem2D } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { concat } from 'rxjs';
import { AnimationPlay } from '../../../scripts/libs/rxjs/cc3/AnimationPlay';
import { Animation } from 'cc';
import { Timer } from '../../../scripts/libs/rxjs/cc3/CreatorSchedule';
import { instantFunc } from '../../../scripts/libs/rxjs/cc3/CommonObservable';
import { ResourceHelper } from '../../scripts/ResourceHelper';
import { UIOpacity } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Burst4')
export class Burst4 extends Component {

    reset() {
        this.node.clearSubscriptions();
        let smokeNode = this.node.getChildByName('smoke');
        smokeNode.getComponent(UIOpacity).opacity = 0;
    }

    burst() {
        this.node.clearSubscriptions();
        this.getComponentsInChildren(ParticleSystem2D).forEach(_ => _.resetSystem());
        AnimationPlay(this.getComponent(Animation), 'burst4');
        concat(
            Timer(.5, this.node),
            instantFunc(() => {
                this.getComponentsInChildren(ParticleSystem2D).forEach(_ => _.stopSystem());
            }),
            Timer(1, this.node),
        ).subscribe({
            complete: () => {
                this.node.clearSubscriptions();
                ResourceHelper.Burst4Pool.putNode(this.node);
            }
        })
    }

}

